/**
 * 2017年4月29日
 */
package cn.edu.bjtu.entity.impl.local;

import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;

import org.springframework.context.ApplicationEventPublisher;

import cn.edu.bjtu.asyn.event.BuildWord2VecEvent;
import cn.edu.bjtu.entity.impl.AsynModelBuildStateSupportExecuteContext;
import controllers.BaseController;

/**
 * @author Alex
 *
 */
public class Word2VecBuildExecuteContext extends AsynModelBuildStateSupportExecuteContext<String>{

	BaseController source ;
	String username;
	ReadWriteLock lock = null;
	/**
	 * @param publisher
	 * @param date
	 */
	public Word2VecBuildExecuteContext(ApplicationEventPublisher publisher,
			Date date,BaseController source,String username,ReadWriteLock lock) {
		super(publisher, date);
		// TODO Auto-generated constructor stub
		this.source = source;
		this.username = username;
		this.lock = lock;
	}
//BuildWord2VecEvent
	@Override
	protected void fireInternal() {
		publisher.publishEvent(new BuildWord2VecEvent(source, this.username,this));
		this.msg = "Task has been submitted";
	}
	/**
	 * @return the lock
	 */
	@Override
	public ReadWriteLock getLock() {
		return lock;
	}

	/* (non-Javadoc)
	 * @see cn.edu.bjtu.entity.impl.AsynModelBuildStateSupportExecuteContext#executeAsync()
	 */
	@Override
	public void executeAsync() {
		// TODO Auto-generated method stub
		try {
			//fang wen wrod2vec uri 
			System.out.println("给微服务请求数据啊 建立word2vec 这里sleep 20s 模拟阻塞");
			TimeUnit.SECONDS.sleep(20);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	/* (non-Javadoc)
	 * @see cn.edu.bjtu.entity.ExecuteResult#javaClassResult()
	 */
	@Override
	public String javaClassResult() {
		// TODO Auto-generated method stub
		return this.msg;
	}

}
